package com.sskj.video;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @Author: Like
 * @Date: 2023/11/9 09:42
 * @Description:
 */
public class Test1 {
    public static void main(String[] args) throws Exception{
//        String result = ArtemisPostUtil.callPostApiGetOrgList();
        String V1CamerasResult = ArtemisPostUtil.callPostV1Cameras();
//        write(V1CamerasResult);
        JSONObject jsonObject01 = JSON.parseObject(V1CamerasResult);
        JSONObject jsonObject02 = JSON.parseObject(String.valueOf(jsonObject01.get("data")));
        JSONArray jsonArray = JSONArray.parseArray(String.valueOf(jsonObject02.get("list")));
        ArrayList<Object> list = new ArrayList<>();
        for(int i = 0;i<jsonArray.size();i++){
            JSONObject jsonObject03 = JSON.parseObject(String.valueOf(jsonArray.get(i)));
            String cameraIndexCode = (String) jsonObject03.get("cameraIndexCode");
            String VechicleDataResult = ArtemisPostUtil.callPostPreviewURLs(cameraIndexCode,"hls");
            String videoInfo = ArtemisPostUtil.callPostIndexCode(cameraIndexCode);
//            String calledPostTalkURLs = ArtemisPostUtil.callPostTalkURLs(cameraIndexCode);
            JSONObject jsonObject04 = JSON.parseObject(String.valueOf(VechicleDataResult));
            CameraVO cameraVO = CameraVO.builder()
                    .name(jsonObject03.get("cameraName"))
                    .url(jsonObject04.get("data"))
//                    .channelNo(jsonObject03.get("channelNo"))
                    .cameraIndexCode(jsonObject03.get("cameraIndexCode"))
                    .build();
            list.add(cameraVO);
            System.out.println(cameraVO);
//            System.out.println(calledPostTalkURLs);
        }
        System.out.println("总计："+list.size()+"条");
    }
    public static void write(String text) {

        File file = new File("C:\\Users\\Administrator\\Desktop\\test.txt");

        try {
            FileWriter writer = new FileWriter(file);
            writer.write(text);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
